package com.generate.span;


import com.generate.table.Table;
import com.generate.table.Td;
import com.generate.table.Thead;
import com.generate.table.Tr;

import java.util.Arrays;
import java.util.Comparator;

public interface TableCallBack<T extends Table> extends Comparator<Integer> {


    T create();


    default void init(T table) {

    }

    void build(T table);

    @Override
    default int compare(Integer o1, Integer o2) {
        return 0;
    }

    default void boldTr(Tr tr) {
        tr.getTdList().forEach(this::boldTd);
    }

    default void boldTr(Tr... trs) {
        Arrays.stream(trs).forEach(this::boldTr);
    }

    default Td boldTd(Td td) {
        return td.setStyle("font-weight: bold;" + td.getStyle());
    }

    default void boldTd(Td... tds) {
        Arrays.stream(tds).forEach(this::boldTd);
    }

    default void boldThead(Thead thead) {
        thead.getTrs().forEach(this::boldTr);
    }


    default void yellowBgTd(Td td) {
        td.setStyle("background-color:#feee98;");
    }


    default void yellowBgTr(Tr tr) {
        tr.getTdList().forEach(this::yellowBgTd);
    }

    default void yellowBgTd(Td... tds) {
        Arrays.stream(tds).forEach(this::yellowBgTd);
    }

    default void yellowBgTr(Tr... trs) {
        Arrays.stream(trs).forEach(this::yellowBgTr);
    }



    default void yellowBgAndBoldTr(Td td) {
        td.setStyle("background-color:#feee98;font-weight: bold;");
    }


    default void yellowBgAndBoldTr(Tr tr) {
        tr.getTdList().forEach(this::yellowBgAndBoldTr);
    }

    default void yellowBgAndBoldTr(Td... tds) {
        Arrays.stream(tds).forEach(this::yellowBgAndBoldTr);
    }

    default void yellowBgAndBoldTr(Tr... trs) {
        Arrays.stream(trs).forEach(this::yellowBgAndBoldTr);
    }


    default void yellowBgAndBoldThead(Thead thead) {
        thead.getTrs().forEach(this::yellowBgAndBoldTr);
    }
}
